package com.ailot.cloud.upms.api.controller;

import com.ailot.cloud.base.log.annotation.Oplog;
import com.ailot.cloud.upms.api.service.SysDatasourceService;
import com.ailot.cloud.upms.common.entity.SysDatasource;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;
import java.util.List;


/**
 * 数据源管理
 *
 * @author
 */
@RestController
@AllArgsConstructor
@RequestMapping("/ds")
public class SysDatasourceController {

    private final SysDatasourceService sysDatasourceService;

    @GetMapping("/list")
    public List list() {
        return sysDatasourceService.list();
    }


    @GetMapping("/{id}")
    public SysDatasource getById(@PathVariable("id") String id) {
        return sysDatasourceService.getById(id);
    }


    @Oplog("新增数据源表")
    @PostMapping
    public void save(@RequestBody SysDatasource sysDatasource) throws SQLException {
        sysDatasourceService.addSysDatasource(sysDatasource);
    }


    @Oplog("修改数据源表")
    @PutMapping
    public void updateById(@RequestBody SysDatasource sysDatasource) throws SQLException {
        sysDatasourceService.updateSysDatasource(sysDatasource);
    }

    @Oplog("删除数据源")
    @DeleteMapping("/{id}")
    public void removeById(@PathVariable String id) {
        sysDatasourceService.removeById(id);
    }

}
